package com.ssy.lingxi.platform.template.service.repository;
import com.ssy.lingxi.platform.template.service.entity.door.MemberShop;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MemberShopRepository extends JpaRepository<MemberShop, Long> {

    MemberShop findByMemberIdAndRoleId(Long memberId, Long roleId);

    Boolean existsByMemberIdAndRoleId(Long memberId, Long roleId);

    @Query(value = "SELECT * FROM pt_member_shop WHERE create_time > :timeInMillis ORDER BY create_time DESC limit 5", nativeQuery = true)
    List<MemberShop> findNewAddMemberShop(@Param("timeInMillis") long timeInMillis);

    Long countByMemberIdIn(List<Long> memberIds);

    List<MemberShop> findAllByIdNotIn(List<Long> memberIds);

    Page<MemberShop> findAllByIdNotIn(List<Long> memberIds, Pageable pageable);

    List<MemberShop> findAllByIdIn(List<Long> ids);

    Page<MemberShop> findAllByIdIn(List<Long> idList, Pageable pageable);

    Page<MemberShop> findAllByIdNotInAndMemberNameContains(List<Long> idList, String memberName, Pageable pageable);

    List<MemberShop> findByRoleId(Long roleId);

    List<MemberShop> findByMemberIdIn(List<Long> memberIdList);

    Page<MemberShop> findAllByCreateTimeGreaterThanEqual(Long time, Pageable pageable);

    Page<MemberShop> findAllByMemberNameContains(String key, Pageable pageable);
}
